package org.aeon.client.view.components.sessionPanel;

import org.aeon.client.view.components.listColumn.ColumnScrollPanel;
import org.aeon.entity.dto.GroupInfoDto;
import org.aeon.utils.SwingUtil;

import javax.swing.*;
import java.awt.*;

/**
 * @author: MissingAeon
 * @date: 2024/2/21 8:55
 * @description:
 */
public class GroupMemberPanel extends JPanel {

    private final ColumnScrollPanel scrollPanel;

    public GroupMemberPanel(Dimension preferredSize) {
        SwingUtil.setSize(this, preferredSize);

        final Box box = Box.createVerticalBox();
        // 设置 Box 左对齐
        box.add(Box.createVerticalStrut(5));

        final JLabel title = new JLabel("群成员");
        title.setFont(new Font("黑体", Font.BOLD, 22));
        // 设置标题标签左对齐
        title.setAlignmentX(Component.LEFT_ALIGNMENT);
        box.add(title);

        box.add(Box.createVerticalStrut(5));

        // content = new JLabel("这是群成员....");
        // content.setFont(new Font("黑体", Font.PLAIN, 14));
        // content.setAlignmentX(Component.LEFT_ALIGNMENT);
        // box.add(content);

        scrollPanel = new ColumnScrollPanel(new Dimension(193, 420));
        scrollPanel.setBorder(null);
        box.add(scrollPanel);

        this.add(box);
    }

    public void load(GroupInfoDto group) {
        group.getMembers().forEach(member -> {
            final JButton button = new JButton(member.getNickname());
            button.setContentAreaFilled(false);
            button.setFocusPainted(false);
            SwingUtil.setSize(button, new Dimension(180, 30));
            scrollPanel.addItem(button);
        });
    }
}
